package online.shenjian.mq;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnProperty(name = "spring.rabbitmq.enable", matchIfMissing = true)
public class RpcServer {

    @RabbitListener(queues = "rpc.requests")
    public int fibonacci(int n) {
        System.out.println(" [服务端] 收到请求" + n);
        int result = fib(n);
        System.out.println(" [服务端] 响应请求 " + result);
        return result;
    }

    public int fib(int n) {
        return n == 0 ? 0 : n == 1 ? 1 : (fib(n - 1) + fib(n - 2));
    }

}